package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
@RequiredArgsConstructor
@Slf4j
public class DeviceController extends BaseController{

    private final DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public ResponseResult<Void> syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        log.info("查询所有产品列表");
      List<ProductVo> productVoList = deviceService.allProduct();
        return success(productVoList);
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto) {
        log.info("注册设备，设备参数：{}",deviceDto);
        return deviceService.registerDevice(deviceDto);
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        log.info("分页查询设备列表参数，{}",devicePageQueryDto);
        PageResponse<DeviceVo> page = deviceService.pageQueryDevice(devicePageQueryDto);
        return success(page);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详细数据")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request) {
      DeviceVo deviceVo  =  deviceService.queryDeviceDetail(request);
        return success(deviceVo);
    }


    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查询指定产品的已发布物模型中的功能定义")
    public ResponseResult queryThingModelPublished(
            @RequestBody QueryThingModelPublishedRequest request) {
        return  deviceService.queryThingModelPublished(request);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定产品的已发布物模型中的功能定义")
    public ResponseResult queryDevicePropertyStatus(
            @RequestBody QueryDevicePropertyStatusRequest request) {
        return  deviceService.queryDevicePropertyStatus(request);
    }


    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "查询指定产品的已发布物模型中的功能定义")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto dto) {
        return  deviceService.UpdateDevice(dto);
    }

    //删除设备
    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult UpdateDevice(
            @RequestBody DeleteDeviceRequest request) {
        return  deviceService.deleteDevice(request);
    }
}